package com.demo;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.BlockLocation;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;



public class FirstDemo {
	public static void main(String[] args) throws IOException, URISyntaxException {
		Configuration conf=new Configuration();
		conf.set("dfs.replication","1");
		FileSystem fs=FileSystem.get(new URI("hdfs://10.9.124.187:9000"), conf);
		
//		InputStream in=fs.open(new Path("/park01/3.txt"));
//		
//		OutputStream out = new FileOutputStream(new File("a.txt"));
//		InputStream in=new FileInputStream("src/com/demo/FirstDemo.java");
//		OutputStream out = fs.create(new Path("/park10/demo.java"));
//		fs.delete(new Path("/park10/xxx"), true);
		BlockLocation[] fileBlockLocations = fs.getFileBlockLocations(new Path("/park10/kejianv4.zip"), 0, Integer.MAX_VALUE);
		for (int i = 0; i < fileBlockLocations.length; i++) {
			System.out.println(fileBlockLocations[i]);
		}
		//IOUtils.copyBytes(in, out,conf);
//		in.close();
//		out.close();
		fs.close();
	}
}
